package com.bao.wechat.activity.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bao.wechat.activity.entity.XtjActivity;
import com.bao.wechat.activity.service.IXtjActivityService;
import com.bao.wechat.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bao
 */

@RestController
@RequestMapping(value = "/xtjActivity", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class XtjActivityController extends ApiController {

	@Autowired
	private IXtjActivityService activityService;

	/**
	 * 任务列表
	 * @Description
	 *  @author bao
	 *  @data Jul 1, 2020 9:02:30 AM
	 */
	@RequestMapping(value = "/getActivityList")
	public R getActivityList(XtjActivity activity,Integer page,Integer limit){
		Page p = new Page<XtjActivity>(page,limit);
		QueryWrapper<XtjActivity> queryWrapper = new QueryWrapper<XtjActivity>();
		activity.setStatus(0);
		queryWrapper.setEntity(activity);
		List<XtjActivity> list = activityService.page(p,queryWrapper).getRecords();
		return  R.ok().put("data",list).put("code", 0).put("count", list.size());
	}

	/**
	 * 软删除任务
	 * @Description
	 *  @author bao
	 *  @data Jul 1, 2020 9:03:59 AM
	 */
	@RequestMapping(value = "/ActivityDelete")
	public R ActivityDelete(String id){
		XtjActivity xtjActivity = activityService.getById(id);
		xtjActivity.setStatus(1);
		activityService.updateById(xtjActivity);
		return  R.ok();
	}
	
	/**
	 * 新增任务
	 * @Description
	 *  @author bao
	 *  @data Jul 1, 2020 9:03:59 AM
	 */
	@RequestMapping(value = "/ActivityAdd")
	public R ActivityAdd(String name){
		XtjActivity xtjActivity = new XtjActivity();
		xtjActivity.setName(name+".xls");
		activityService.save(xtjActivity);
		return  R.ok();
	}

}
